<template>
  <el-container class="goods-stock">
    <el-main>
      <el-form :model="form.model" :rules="form.rules" ref="formRef" label-width="100px">
        <el-form-item label="回复内容" prop="content">
          <el-input v-model="form.model.content" placeholder="请输入回复内容"></el-input>
        </el-form-item>
      </el-form>
    </el-main>
    <el-footer class="sa-footer--submit">
      <el-button type="primary" @click="confirm">确 定</el-button>
    </el-footer>
  </el-container>
</template>
<script setup>
  import { reactive, ref, unref } from 'vue';
  import { api } from '../goods.service';
  import { cloneDeep } from 'lodash';

  const emit = defineEmits(['modalCallBack']);
  const props = defineProps({
    modal: {
      type: Object,
    },
  });
  const loading = ref(false);
  // 添加 编辑 form
  let formRef = ref(null);
  const form = reactive({
    model: {
      content: '',
    },
    rules: {
      content: [{ required: true, message: '请输入回复内容', trigger: 'change' }],
    },
  });
  async function confirm() {
    // 表单验证
    unref(formRef).validate(async (valid) => {
      if (!valid) return;
      let submitForm = cloneDeep(form.model);
      const { error } = await api.comment.reply(props.modal.params.id, submitForm);
      if (error == 0) {
        emit('modalCallBack', {
          event: 'confirm',
        });
      }
    });
  }
</script>
